#ifndef PACKETSTREAM_H
#define PACKETSTREAM_H

#include "enet/enet.h"
#include <cstring>

class PacketClass 
{
public:
	PacketClass(char _type, ENetPacketFlag _flag=ENET_PACKET_FLAG_RELIABLE, enet_uint8 _chanel=0);
	PacketClass(ENetPacket *_packet);

	ENetPacket* GetENetPacket() { return m_Packet; }
	enet_uint8 GetChannel() { return m_Channel; }
	void Shrink();

	void WriteBit(bool _data);
	void WriteChar(char _data);
	void WriteInt(int _data);
	void WriteFloat(float _data);
	void WriteString(const char* _data);

	bool  ReadBit();
	char  ReadChar();
	int   ReadInt();
	float ReadFloat();
	const char *ReadString();

private:
	void AlignBitIndex();
	void AlignAndExpand(int _newSize);

	ENetPacket* m_Packet;
	enet_uint8 m_Channel;		
	enet_uint32 m_CurrentByte;
	enet_uint32 m_CurrentBit;
};

#endif
